

package cn.shengchao.controler;

import cn.shengchao.util.helper.LoginHelper;
import cn.shengchao.examstar.me.address.ohs.local.appservices.AddressAppService;
import cn.shengchao.examstar.me.address.ohs.local.message.AddressDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.continew.starter.web.model.R;

import java.util.List;

@RestController
@Slf4j
@CrossOrigin("${project.cross-origin}")
@RequestMapping("/api/${project.version}/address")
public class AddressController {

    @Autowired
    private AddressAppService addressAppService;

    @PostMapping
    public R saveAddress(@RequestBody AddressDto address) {
        Long uid = LoginHelper.getUserId();
        addressAppService.saveAddress(address, uid);
        return R.ok();
    }

    @GetMapping
    public List<AddressDto> getList() {
        Long uid = LoginHelper.getUserId();
        return addressAppService.getList(uid);
    }

    @GetMapping("default")
    public AddressDto defaultAddress() {
        Long uid = LoginHelper.getUserId();
        return addressAppService.defaultAddress(uid);
    }

}
